package com.tx.mq.producer;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class LogProducer {
    private static final String EXCHANGE_NAME = "logs";
    private static final String QUEUE_NAME = "log_queue";
    public static void main(String[] args) {
        ConnectionFactory cf = new ConnectionFactory();
        cf.setHost("localhost");

        try (Connection connection = cf.newConnection()) {
            Channel channel = connection.createChannel();
            channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
//            channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "");
            String message = "hello world2";
            channel.basicPublish(EXCHANGE_NAME, "", null , message.getBytes());
            System.out.println("[x] Sent '" + message + "'");
        } catch (TimeoutException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
